<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title></title>
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../css/list.css" />
	<style>
		.y_tbl {
			width: 100%;
			margin: 15px 0;
			padding-top: 3px;
			text-align: center;
			background: #E5E5E5;
		}

		.y_tbl td {
			border: solid 1px #6F6C6C;
		}

		#content {
			/*width: 500px;*/
			/*background-color: #ccc;*/
			line-height: 26px;
		}

		a {
			text-decoration: none;
			color: red;
		}

		.starspantextc img {
			width: 15px;
		}
	</style>
</head>

<body>
	<div class="h10"></div>
	<div id="main_content">

		<!-- <div class="main_content" tapmode="presshover">
			<div class="cnt">
				<div class="wrap">
					<div class="wrap2">
						<div class="content">
							<div><img src="../image/btn/backed.png">测试标题</div>

							<div>
								<table class="y_tbl">
									<tr>
										<td style="width:15%"><b>时间</b></td>
										<td style="width:7%"><b>状态</b></td>
										<td><b>详情</b></td>
									</tr>
									<tr>
										<td>2015-05-09 00:11:11</td>
										<td>处置完成</td>
										<td>
											<div id="content">
												测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题测试标题
											</div>
										</td>
									</tr>
								</table>
							</div>

							<div class="info">
								<a class="symbol">测试</a>
								<a class="price">2015-05-09 00:15:00</a>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div> -->


	</div>
	<div id="divNoDataTip">
		<div id="textTip" style="margin-top:10px;margin-bottom:10px;width:100%;text-align: center;" class="button red" tapmode="">正在加载..</div>
	</div>
	<div id='copyobj' style="display:none;"></div>
	<div class="h10"></div>
	<input id="pageIndex" type="hidden" value="0" />
	<input id="pageSize" type="hidden" value="20" />
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/alpenlicebe.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hashes.min.js"></script>
<script type="text/javascript" src="../script/raty/demo/js/jquery.min.js"></script>
<script type="text/javascript" src="../script/raty/lib/jquery.raty.min.js"></script>
<script>
	apiready = function() {
		/*如果用户处理了，进行刷新*/
		api.addEventListener({
			name: 'Alpe_Event_yq_dosomething'
		}, function(ret) {
			if (ret) {

				$("#pageIndex").val(0);
				$("#main_content").html("");
				$("#textTip").html("正在加载..");
				goto_loadDataFun();

			}
		});
		/*注册监听事件-用户登录*/
		api.addEventListener({
			name: 'Alpe_Event_UserLogin'
		}, function(ret) {
			if (ret) {
				$("#pageIndex").val(0);
				$("#main_content").html("");
				$("#textTip").html("正在加载..");
				goto_loadDataFun();
			}
		});


		/*下拉刷新*/
		api.setRefreshHeaderInfo({
			visible: true,
			loadingImg: 'widget://image/refresh.png',
			bgColor: '#fff',
			textColor: '#000',
			textDown: '下拉刷新...',
			textUp: '松开刷新...',
			showTime: true
		}, function(ret, err) {
			$("#pageIndex").val(0);
			$("#main_content").html("");
			$("#textTip").html("正在加载..");
			goto_loadDataFun();
			api.refreshHeaderLoadDone();
		});

		/*滑动到底部加载数据*/
		api.addEventListener({
			name: 'scrolltobottom'
		}, function(ret, err) {
			goto_loadDataFun();
		});

		/*初始化加载数据*/
		goto_loadDataFun();
	}

	function goto_loadDataFun() {
		goto_loadNewsListFun();
		api.parseTapmode();


	}

	function goto_loadNewsListFun() {
		var userID = Alpe_getLocalStorge('access_token');
		if ('' == userID) {
			api.alert({
				title: '系统提示',
				msg: '您未登录'
			});
			return;
		}
		var pageIndex = parseInt($("#pageIndex").val()) + 1;
		var pageSize = $("#pageSize").val();
		$("#pageIndex").val(pageIndex);

		api.showProgress({
			style: 'default',
			animationType: 'fade',
			title: '',
			text: '',
			modal: false
		});

		var MD5 = new Hashes.MD5;
		var access_token = Alpe_getLocalStorge("access_token");
		var admin_id = Alpe_getLocalStorge("admin_id");
		var sign = MD5.hex(access_token + admin_id + pageIndex + 'datas/getMsglist1.0syjqingbao');

		var url = Alpe_ApiUrl + 'r=datas/getMsglist&access_token=' + access_token + '&admin_id=' + admin_id +
			'&page=' + pageIndex + '&catetype=' + api.pageParam.index +
			'&v=1.0&sign=' + sign;
		console.log(url);
		api.ajax({
			url: url,
			method: 'get',
			cache: false,
			timeout: 30,
			dataType: 'json',
			async: false
		}, function(ret, err) {
			if (ret) {
				if (ret.success == '100') {
					if (ret.msgdatalist.length < pageSize) {
						api.removeEventListener({
							name: 'scrolltobottom'
						});
						$("#textTip").html("暂无更多数据");
					}
					$.each(ret.msgdatalist, function(index, v) {
						var style = "#333";
						if (v.is_read == 1) {
							style = "#919193";
						}
						var is_back = '';
						if (v.is_back == 1) {
							is_back = '<img style="position: relative;top: 7px;" src="../image/btn/backed.png">';
						}
						var is_timeout = '';
						// if (v.is_timeout == 1) {
						// 	is_timeout = '<img style="position: relative;top: 7px;" src="../image/btn/timeout.png">';
						// }
						var tmpHtml = '<div data-id="' + (index + pageSize * pageIndex) + '" id=' + v.message_id + ' class="main_content" tapmode="presshover"><div class="cnt"><div class="wrap"><div class="wrap2"><div class="content"><div id="tit_' + v.message_id +
							'"  onclick="goto_openDetailWinFun(' + v.message_id +
							')" class="shopname" style="color:' + style +
							';">' + is_back + is_timeout + v.title + '</div>';
						if (v.suggestion_array.length > 0) {
							tmpHtml += '<div><table class="y_tbl">' +
								'<tr>' +
								'<td style="width:90px"><b>时间</b></td>' +
								'<td style="width:70px"><b>状态</b></td>' +
								'<td><b>详情</b></td>' +
								'</tr>';
							$.each(v.suggestion_array, function(i, m) {

								var str = m.status;
								var display = 'none';
								if (i == v.suggestion_array.length - 1) {
									display = '';
								}
								if (m.is_copy == 1) {
									tmpHtml += '<tr class="deallisttr ' + display + '" style="display:' + display + '">' +
										// '<input type="hidden" value="'+m.img_path+'" />'+
										'<td>' + m.time + '</td>' +
										'<td>' + m.status + '</td>' +
										'<td style="text-align:left;">' + '<input class="imgpath" type="hidden" value="' + m.img_path + '" /><div  id="' + v.message_id + 'copy' + i + '">' + m.content + '</div>' +
										'<div style="margin:10px;float:right"><span style="background:#3A8B7A;color:#fff;padding:4px 12px;font-size:12px;" onclick="longPress(\'' +
										v.message_id + 'copy' + i + '\');">复制<span/></div>' + '</td>' +
										'</tr>';

								} else {
									tmpHtml += '<tr class="deallisttr ' + display + '" style="display:' + display + '">' +
										'<td>' + m.time + '</td>' +
										'<td>' + m.status + '</td>' +
										'<td style="text-align:left;">' + m.content + '</td>' +
										'</tr>';
								}
							});
							tmpHtml += '</table></div>';
						}
						if (v.is_daishenhe == 1) {
							tmpHtml += '<div style="color:green;float:left;font-size:14px;padding-bottom:10px;" lang="0">待审核</div>';
						}
						if (v.suggestion_array.length > 1) {
							tmpHtml += '<div class="zhankaitr" style="color:blue;float:right;font-size:14px;padding-bottom:10px;" onclick="gotozhankai(this);" lang="0">全部记录</div>';
						}
						tmpHtml += '<div class="info" style="clear:both;"><a class="symbol">' + v.media_name +
							'</a><a class="price">' + v.send_time + '</a></div></div></div></div></div></div>';
						$("#main_content").append(tmpHtml);
					});
				} else if ("002" == ret.success || "003" == ret.success) {
					goto_openWin_loginWin(ret.message);
				} else {
					api.removeEventListener({
						name: 'scrolltobottom'
					});
					$("#textTip").html(ret.message);
					api.toast({
						msg: ret.message,
						duration: 2000,
						location: 'middle'
					});
				}
				api.hideProgress();
			} else {
				api.alert({
					title: '系统提示',
					msg: '错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode
				});
				api.hideProgress();
			}
		});
	}

	function gotozhankai(obj, event) {
		stopBubbling(event);
		var lang = $(obj).attr('lang');
		if (lang == 0) {
			$(obj).parents('.main_content').find('.y_tbl').find('.none').show();
			$(obj).attr('lang', '1');
			$(obj).html('最新记录');
		}

		if (lang == 1) {
			$(obj).parents('.main_content').find('.y_tbl').find('.none').hide();
			$(obj).attr('lang', '0');
			$(obj).html('全部记录');

			var index = $(obj).parents('.main_content').attr("data-id");
			// alert(index);
			var TotalTrheight = getTotalTrheight(index);
			$(window).scrollTop(TotalTrheight);
		}

	}


	function gotoImage(obj, event) {
		stopBubbling(event);
		var imgpath = $(obj).parents('td').find('.imgpath').val();
		var strs = new Array(); //定义一数组
		strs = imgpath.split("|"); //字符分割
		var obj = api.require('imageBrowser');
		obj.openImages({
			imageUrls: strs,
			showList: false,
			activeIndex: 0
		});
	}
	//	复制功能
	function longPress(message_id, event) {
		stopBubbling(event);
		var copytext = $("#" + message_id).text();
		var clipBoard = api.require('clipBoard');
		clipBoard.set({
			value: copytext
		}, function(ret, err) {
			if (ret) {
				api.toast({
					msg: '复制成功',
					duration: 1500,
					location: 'bottom',
					global: true
				});
			} else {

			}
		});
		return false;
	}

	function stopBubbling(e) {
		e = window.event || e;
		if (e.stopPropagation) {
			e.stopPropagation(); //阻止事件 冒泡传播
		} else {
			e.cancelBubble = true; //ie兼容
		}
	}

	function init(pageIndex) {

		var len = 78; //默认显示字数
		var content = "";
		var message_id = "";
		var html = "";
		var content_font = "";
		var content_sub = "";
		var content_sub_font = "";
		$(".tdcontent" + pageIndex).each(function() {
			message_id = $(this).attr("message_id");
			content = $(this).html();
			content_font = content.replace("【点击查看处置报告图片】", "<font color='#E1282A' onclick='goto_openDetailWinFun(\"" + message_id + "\")'>【点击查看处置报告图片】</font>");
			// alert($(this).scrollTop());

			content_sub = content.substring(0, len);
			content_sub_font = content_sub.replace("【点击查看处置报告图片】", "<font color='#E1282A' onclick='goto_openDetailWinFun(\"" + message_id + "\")'>【点击查看处置报告图片】</font>");
			html = '<span class="allstr" style="display:none;">' + content_font + '</span>';
			html += '<span class="substr" >' + content_sub_font + '</span>';
			if (content.length > len) {
				html += '<a class="zhedie" href="javascript:void(0)" onclick="openAllcontent(this);" >... 展开</a>';
			}
			$(this).html('');
			$(this).html(html);
		});

	}

	//计算之前所有div块的高度
	function getTotalTrheight(index) {
		var totalTrheight = 0;
		var trheight = 0;
		$(".main_content").each(function() {
			var num = $(this).attr("data-id");
			trheight = $(this).height();
			if (num < index) {
				totalTrheight = totalTrheight + parseInt(trheight);
			}
		});
		return totalTrheight;
	}

	function openAllcontent(obj) {

		if ($(obj).html().indexOf("展开") > 0) {
			$(obj).html("<<&nbsp;收起");
			$(obj).parent().find(".allstr").show();
			$(obj).parent().find(".substr").hide();
		} else {
			var index = $(obj).parents('.main_content').attr("data-id");
			// alert(index);
			var TotalTrheight = getTotalTrheight(index);
			$(obj).html("... 展开");
			$(window).scrollTop(TotalTrheight);
			$(obj).parent().find(".substr").show();
			$(obj).parent().find(".allstr").hide();
		}
	}

	function goto_openDetailWinFun(infoID) {

		$("#tit_" + infoID).css('color', '#919193');
		var delay = 0;
		if ("ios" != api.systemType) {
			delay = 300;
		}
		api.openWin({
			name: 'yq_listDetail',
			url: './yq_listDetail.html',
			bounces: false,
			reload: true,
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			pageParam: {
				infoID: infoID,
				is_button:1
			},
			delay: delay
		});
	}
</script>

</html>
